package requests

import (
	"WeChatMGRA/modul"
	"encoding/json"
	"errors"
)

//QuitGroup 退出微信群
func QuitGroup(wid,chatroom string)error{
	resp_data,err := MakeARequest("delGroupContact",[]byte("{\"wId\": \""+wid+"\",\"chatroom\": \""+chatroom+"\"}"))
	if err!=nil{
		return err
	}
	mvmsg := modul.GetBaseMsg()
	if err := json.Unmarshal(resp_data,mvmsg);err!=nil{
		return err
	}
	if mvmsg.Code == "1000"{
		return nil
	}
	modul.GiveBaseMsg(mvmsg)
	return errors.New("发送错误")
}

//拉取群成员信息
func GetChatRoomMember(wid,chatroom string)([]modul.ChatRoomMember,error){
	resp_data,err := MakeARequest("getChatRoomMember",[]byte("{\"wId\": \""+wid+"\",\"chatroom\": \""+chatroom+"\"}"))
	if err!=nil{
		return nil,err
	}
	mvmsg := modul.GetBaseMsg()
	if err := json.Unmarshal(resp_data,mvmsg);err!=nil{
		return nil,err
	}
	if mvmsg.Code != "1000"{
		return nil,errors.New("群成员信息获取错误")
	}
	data,_:=json.Marshal(mvmsg.Data)
	allwx := make([]modul.ChatRoomMember,0)
	if err=json.Unmarshal(data,&allwx);err!=nil{
		return  nil,err
	}
	modul.GiveBaseMsg(mvmsg)
	return allwx,nil
}